package com.ysd.lis.controller.callNum;


import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.callNum.CallWindow;
import com.ysd.lis.service.callNum.CallWindowService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wh
 * @since 2025-05-28
 */
@RestController
@RequestMapping("/callNum/window")
public class CallWindowController extends BaseController {

    @Autowired
    private CallWindowService callWindowService;

    @ApiOperation("获取采样类型列表")
    @GetMapping("/findWindowList")
    public Result findWindowList() {
        return callWindowService.findWindowList();
    }

    @ApiOperation("编辑功能")
    @PostMapping("/addOrEditWindow")
    public Result addOrEditWindow(@RequestBody CallWindow callWindow) {
        boolean b = callWindowService.saveOrUpdate(callWindow);
        if (b) {
            return Result.succ(1, "保存成功", "");
        } else {
            return Result.succ(400, "保存失败", "");
        }
    }

    @ApiOperation("批量删除")
    @PostMapping("/batchDeleteWindow")
    public Result batchDeleteWindow(@RequestBody List<CallWindow> callWindows) {
        List<String> ids = callWindows.stream().map(CallWindow::getId).collect(Collectors.toList());
        boolean b = callWindowService.removeByIds(ids);
        if (b) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail(400, "删除失败", "");
        }
    }

}
